package com.chen.conf;

import com.chen.entity.Klass;
import com.chen.entity.Student;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;

import java.util.ArrayList;
import java.util.List;

@Data
public class KlassConfiguration {

    private List<Klass> klasses;

    @Autowired
    private SchoolProperties schoolProperties;

    @Bean
    public void assignClass(){
        List<Student> students = schoolProperties.getStudents();
        klasses = new ArrayList<>();
        if (students.size() > 0){
            Klass klass = null;
            for (int i =0;i< students.size();i++){
                if (i%2 == 0){
                    klass = new Klass("班级"+ i);//两个人一个班级
                    klasses.add(klass);
                }
                klass.addStudent(students.get(i));
            }
        }
    }
}
